package com.ljx.singleMode;

/**
 * 饿汉加载单例模式
 * 基于JVM类加载 保证线程安全
 * @作者 LJX
 * @日期 2022/12/9 16:30
 */
public class HungrySingletonTest {

    public static void main(String[] args) {
        HungrySingleton instance = HungrySingleton.getInstance();
        HungrySingleton hs = HungrySingleton.getInstance();
        System.out.println(instance == hs);
    }

}

class HungrySingleton{

    private static HungrySingleton INSTANCE = new HungrySingleton();

    private HungrySingleton(){}

    public static HungrySingleton getInstance(){
        return INSTANCE;
    }
}
